<?php Temp::Tinclude("commom/admin_header");?>
 <div class="padding_left_right">
<div class="panel panel-default">
  <div class="panel-heading">添加（菜）分类</div>
  <div class="panel-body">
     
      <form class="form" role="form" action="index.php?<?php echo $jp_arg['c'];?>/<?php echo $jp_arg['a'];?>"  method="post">   
          <input type="hidden" name="id" value="<?php echo $id;?>"/>
<div class="form-group input-group col-md-6">
   
    <span class="input-group-addon" id="basic-addon1">菜分类名称:</span>
    <input type="text" name="base_name" value="<?php echo $cate['base_name'];?>" class="form-control" placeholder="名称" aria-describedby="basic-addon1">

</div>
   
 <div class="form-group form-inline menuparent">
 <?php foreach($pinfo as $k=>$val){?>
     <?php if($k==0){?>
     <select class="form-control parent_id" name="parent_id[]">
      <option value="0">顶级分类</option>
 
          <?php foreach($val["data"] as $value){?>
         
          <option value="<?php echo $value['id'];?>" <?php if($value["id"]==$val["selected"]) echo "selected";?> ><?php echo $value['base_name'];?></option>
        
  
         <?php }?>
  </select>
     <?php }else{?>
     <span class="menuchildrenall">  
         <select class="form-control col-md-1 col-xs-4 menuchildren"  onchange="menuselectchange(this)" name="parent_id[]">
          <option value="-1">请选择分类</option>
    
          <?php foreach($val["data"] as $value){?>
           <option value="<?php echo $value['id'];?>" <?php if($value["id"]==$val["selected"]) echo "selected";?> ><?php echo $value['base_name'];?></option>
          <?php }?>
       
         
  </select>

</span>
     <?php }?>
     <?php }?>

     

     
     
 </div>
          <div class="form-group input-group col-md-12 col-xs-12">
              <textarea class="form-control" rows="3" name="desc" placeholder="分类描述"><?php echo $cate['desc'];?></textarea>
          </div>   
         

         

<div class="form-group input-group col-md-1">
   
    <span class="input-group-addon" id="basic-addon1">排序:</span>
    <input type="text" name="sort" value="<?php echo $cate['sort'];?>" class="form-control" placeholder="排序" aria-describedby="basic-addon1">

</div>
          

          
          
           <div class="form-group input-group col-md-4">
            <input class="btn btn-default" type="submit" name="submit" value="提交">
           </div>




  </form>
     
  </div>
</div>

<script>
    function menuselectchange(obj){
             var cid=$(obj).val();

             
         
             var thisobj=$(obj).parent();
                if(cid>0){
                 
               
              
                  $.post("?goodcate/public_get_children",{"parent_id":cid,"curid":<?php echo $id;?>},function(data){
                  $(".menuchildrenall").each(function(){
                      if($(this).index()>thisobj.index()){
                          $(this).remove();
                      }
                  });
                  text=data.replace(/(^\s*)|(\s*$)/g,'');
                  if(text.length>0){
                  $(".menuparent").append(data);
                  }
                 
      });
             }

        }
    $('.parent_id').bind('change', function () {
      var cid=$(this).val();
      var parent=$(this).parent();
    
      if(cid!=0){
      
      $.post("?goodcate/public_get_children",{"parent_id":cid,"curid":<?php echo $id;?>},function(data){
          $(".menuchildrenall").remove();
          parent.append(data);
         
      });
    }else{
      
        $(".menuchildrenall").remove();
    }
    });
    
    
    
</script>
 </div>
<?php Temp::Tinclude("commom/admin_footer");?>